/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.stat;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import org.json.JSONArray;
import org.json.JSONObject;

public class t {
    private static String a = "QData";
    private static String b = "";

    public static void a(Context paramContext, String paramString1, String paramString2) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        localSharedPreferences.edit().putString(paramString1, paramString2).commit();
    }

    public static void a(Context paramContext, String paramString, long paramLong) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        localSharedPreferences.edit().putLong(paramString, paramLong).commit();
    }

    public static String b(Context paramContext, String paramString1, String paramString2) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        return localSharedPreferences.getString(paramString1, paramString2);
    }

    public static long b(Context paramContext, String paramString, long paramLong) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        return localSharedPreferences.getLong(paramString, paramLong);
    }

    public static void a(Context paramContext) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        long l = localSharedPreferences.getLong("totalSession", 0L) + 1L;
        localSharedPreferences.edit().putLong("totalSession", l).commit();
    }

    public static void b(Context paramContext) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        String str1 = b(paramContext, "day", "");
        String str2 = ai.m();
        if (str2.equals(str1)) {
            long l = localSharedPreferences.getLong("todaySession", 0L) + 1L;
            localSharedPreferences.edit().putLong("todaySession", l).commit();
        }
        else {
            localSharedPreferences.edit().putString("day", str2).commit();
            localSharedPreferences.edit().putLong("todaySession", 1L).commit();
        }
    }

    public static void a(Context paramContext, String paramString) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        localSharedPreferences.edit().putString("channel", paramString).commit();
    }

    public static void c(Context paramContext) {
        if (!("true".equals(b(paramContext, "enableMode", "true"))))
            return;
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        localSharedPreferences.edit().putString("dataMode", "false").commit();
        ac.f = false;
    }

    public static void d(Context paramContext) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
        localSharedPreferences.edit().putString("dataMode", "true").commit();
        ac.f = true;
    }

    public static String b(Context paramContext, String paramString) {
        String str = "";
        str = e(paramContext);
        if ("qch_default".equals(str)) {
            SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qihoo_game_session_info", 0);
            str = localSharedPreferences.getString("channel", paramString);
        }
        else if ((str.length() == 16) && (str.startsWith("qch_" + ai.n()))
                && (ai.i() + ai.j().equals(ai.a(str.substring(10))))) {
            ac.a = true;
            str = "";
        }
        return str;
    }

    public static String e(Context paramContext) {
        try {
            if (!(TextUtils.isEmpty(b)))
                return b;
            String str1 = paramContext.getApplicationInfo().sourceDir;
            if (TextUtils.isEmpty(str1))
                break label114;
            String str2 = e.a(str1);
            if (TextUtils.isEmpty(str2))
                break label114;
            if ((str2.startsWith("err")) && (str2.length() > "err".length()))
                str2 = "qch_" + "default" + str2.substring("err".length());
            if (TextUtils.isEmpty(str2))
                break label114;
            b = str2;
            return b;
        } catch (Exception localException) {
            x.a(a, localException);
        }
        label114: return "qch_default";
    }

    public static synchronized void a(Context paramContext, boolean paramBoolean) {
        String str1 = "";
        try {
            if ((!(paramBoolean)) && (!(aa.b)) && (!(u.b)) && (!(y.b)) && (!(ag.b)) && (!(r.b)) && (!(ah.b))
                    && (!(ab.b)))
                return;
            n localn = ac.e;
            String str2 = ai.b(ai.r(paramContext));
            try {
                str2 = ai.d(str2);
            } catch (Exception localException2) {
                x.a(a, localException2);
                new File(ai.r(paramContext)).delete();
            } catch (Error localError2) {
                x.a(a, localError2);
                new File(ai.r(paramContext)).delete();
            }
            j localj = new j();
            localj.a(str2);
            JSONObject localJSONObject1 = new JSONObject();
            JSONArray localJSONArray1 = new JSONArray();
            JSONObject localJSONObject2 = null;
            int j;
            if (localj.a != null) {
                localObject1 = null;
                for (int i = 0; i < localj.a.size(); ++i) {
                    localObject1 = (n) localj.a.get(i);
                    if ((((n) localObject1).a.equals(localn.a)) && (paramBoolean)) {
                        localn.e += ((n) localObject1).e;
                        localn.f += ((n) localObject1).f;
                        localObject2 = ((n) localObject1).d;
                        localObject3 = null;
                        if ((localObject2 == null) || (((Vector) localObject2).size() <= 0))
                            continue;
                        if (localn.d == null)
                            localn.d = new Vector();
                        for (j = 0; j < ((Vector) localObject2).size(); ++j) {
                            int k = 0;
                            for (int l = 0; l < localn.d.size(); ++l) {
                                localObject3 = (g) localn.d.get(l);
                                if (!(((g) localObject3).a.equals(((g) ((Vector) localObject2).get(j)).a)))
                                    continue;
                                k = 1;
                                break;
                            }
                            if (k != 0) {
                                x.a(a, "activity: " + ((g) localObject3).a + ",lastDuration: "
                                        + ((g) ((Vector) localObject2).get(j)).d + ",currentDuration: "
                                        + ((g) localObject3).d);
                                localObject3.d += ((g) ((Vector) localObject2).get(j)).d;
                            }
                            else {
                                localn.d.add((g) ((Vector) localObject2).get(j));
                            }
                        }
                    }
                    else {
                        localJSONObject2 = ((n) localObject1).b();
                        localJSONArray1.put(localJSONObject2);
                    }
                }
            }
            if (paramBoolean) {
                localJSONObject2 = localn.b();
                localJSONArray1.put(localJSONObject2);
            }
            if (localJSONArray1.length() > 0)
                localJSONObject1.put("terminate", localJSONArray1);
            Object localObject1 = null;
            JSONArray localJSONArray2 = null;
            Object localObject2 = null;
            Object localObject3 = null;
            if (aa.a != null) {
                localObject1 = new JSONObject();
                localJSONArray2 = new JSONArray();
                for (j = 0; j < aa.a.size(); ++j) {
                    localObject3 = (l) aa.a.get(j);
                    localObject2 = ((l) localObject3).a();
                    localJSONArray2.put(localObject2);
                }
            }
            if (localj.b != null) {
                localObject4 = localj.b.entrySet().iterator();
                localObject5 = null;
                while (((Iterator) localObject4).hasNext()) {
                    localObject6 = (Map.Entry) ((Iterator) localObject4).next();
                    localObject7 = (String) ((Map.Entry) localObject6).getKey();
                    localObject5 = (Vector) ((Map.Entry) localObject6).getValue();
                    if (((String) localObject7).equals(localn.a)) {
                        if (localJSONArray2 == null) {
                            localObject1 = new JSONObject();
                            localJSONArray2 = new JSONArray();
                        }
                        for (int i1 = 0; i1 < ((Vector) localObject5).size(); ++i1) {
                            localObject3 = (l) ((Vector) localObject5).get(i1);
                            localObject2 = ((l) localObject3).a();
                            localJSONArray2.put(localObject2);
                        }
                    }
                    else {
                        JSONArray localJSONArray3 = new JSONArray();
                        for (int i3 = 0; i3 < ((Vector) localObject5).size(); ++i3) {
                            localObject3 = (l) ((Vector) localObject5).get(i3);
                            localObject2 = ((l) localObject3).a();
                            localJSONArray3.put(localObject2);
                        }
                        if (localObject1 == null)
                            localObject1 = new JSONObject();
                        ((JSONObject) localObject1).put((String) localObject7, localJSONArray3);
                    }
                }
            }
            if ((localJSONArray2 != null) && (localObject1 != null))
                ((JSONObject) localObject1).put(localn.a, localJSONArray2);
            if (localObject1 != null)
                localJSONObject1.put("pay", localObject1);
            Object localObject4 = null;
            Object localObject5 = null;
            Object localObject6 = null;
            Object localObject7 = null;
            if (!(TextUtils.isEmpty(ai.b(ai.v(paramContext))))) {
                localObject4 = new JSONObject();
                localObject5 = new JSONArray();
                ai.a((JSONArray) localObject5);
                x.a(a, "Service EventArray size: " + ((JSONArray) localObject5).length());
            }
            if ((u.a != null) && (u.a.size() > 0)) {
                if (localObject4 == null)
                    localObject4 = new JSONObject();
                if (localObject5 == null)
                    localObject5 = new JSONArray();
                for (int i2 = 0; i2 < u.a.size(); ++i2) {
                    localObject7 = (i) u.a.get(i2);
                    if ((!(paramBoolean)) && ("begin".equals(((i) localObject7).c)))
                        continue;
                    localObject6 = ((i) localObject7).a();
                    if (localObject6 == null)
                        continue;
                    ((JSONArray) localObject5).put(localObject6);
                }
            }
            if (localj.c != null) {
                localObject8 = localj.c.entrySet().iterator();
                localObject9 = null;
                while (((Iterator) localObject8).hasNext()) {
                    localObject10 = (Map.Entry) ((Iterator) localObject8).next();
                    localObject11 = (String) ((Map.Entry) localObject10).getKey();
                    localObject9 = (Vector) ((Map.Entry) localObject10).getValue();
                    if (((String) localObject11).equals(localn.a)) {
                        if (localObject5 == null) {
                            localObject4 = new JSONObject();
                            localObject5 = new JSONArray();
                        }
                        for (int i4 = 0; i4 < ((Vector) localObject9).size(); ++i4) {
                            localObject7 = (i) ((Vector) localObject9).get(i4);
                            localObject6 = ((i) localObject7).a();
                            if (localObject6 == null)
                                continue;
                            ((JSONArray) localObject5).put(localObject6);
                        }
                    }
                    else {
                        JSONArray localJSONArray4 = new JSONArray();
                        for (int i6 = 0; i6 < ((Vector) localObject9).size(); ++i6) {
                            localObject7 = (i) ((Vector) localObject9).get(i6);
                            localObject6 = ((i) localObject7).a();
                            if (localObject6 == null)
                                continue;
                            localJSONArray4.put(localObject6);
                        }
                        if (localObject4 == null)
                            localObject4 = new JSONObject();
                        ((JSONObject) localObject4).put((String) localObject11, localJSONArray4);
                    }
                }
            }
            if ((localObject5 != null) && (((JSONArray) localObject5).length() > 0) && (localObject4 != null))
                ((JSONObject) localObject4).put(localn.a, localObject5);
            if ((localObject4 != null) && (((JSONObject) localObject4).length() > 0))
                localJSONObject1.put("event", localObject4);
            Object localObject8 = null;
            Object localObject9 = null;
            Object localObject10 = null;
            Object localObject11 = null;
            if ((y.a != null) && (y.a.size() > 0)) {
                localObject8 = new JSONObject();
                localObject9 = new JSONArray();
                for (int i5 = 0; i5 < y.a.size(); ++i5) {
                    localObject11 = (k) y.a.get(i5);
                    if ((!(paramBoolean)) && (1 == ((k) localObject11).e))
                        continue;
                    localObject10 = ((k) localObject11).a();
                    ((JSONArray) localObject9).put(localObject10);
                }
            }
            if (localj.d != null) {
                localObject12 = localj.d.entrySet().iterator();
                localObject13 = null;
                while (((Iterator) localObject12).hasNext()) {
                    localObject14 = (Map.Entry) ((Iterator) localObject12).next();
                    localObject15 = (String) ((Map.Entry) localObject14).getKey();
                    localObject13 = (Vector) ((Map.Entry) localObject14).getValue();
                    if (((String) localObject15).equals(localn.a)) {
                        if (localObject9 == null) {
                            localObject8 = new JSONObject();
                            localObject9 = new JSONArray();
                        }
                        for (int i7 = 0; i7 < ((Vector) localObject13).size(); ++i7) {
                            localObject11 = (k) ((Vector) localObject13).get(i7);
                            localObject10 = ((k) localObject11).a();
                            ((JSONArray) localObject9).put(localObject10);
                        }
                    }
                    else {
                        JSONArray localJSONArray5 = new JSONArray();
                        for (int i9 = 0; i9 < ((Vector) localObject13).size(); ++i9) {
                            localObject11 = (k) ((Vector) localObject13).get(i9);
                            localObject10 = ((k) localObject11).a();
                            localJSONArray5.put(localObject10);
                        }
                        if (localObject8 == null)
                            localObject8 = new JSONObject();
                        ((JSONObject) localObject8).put((String) localObject15, localJSONArray5);
                    }
                }
            }
            if ((localObject9 != null) && (((JSONArray) localObject9).length() > 0) && (localObject8 != null))
                ((JSONObject) localObject8).put(localn.a, localObject9);
            if ((localObject8 != null) && (((JSONObject) localObject8).length() > 0))
                localJSONObject1.put("level", localObject8);
            Object localObject12 = null;
            Object localObject13 = null;
            Object localObject14 = null;
            Object localObject15 = null;
            if ((ag.a != null) && (ag.a.size() > 0)) {
                localObject12 = new JSONObject();
                localObject13 = new JSONArray();
                for (int i8 = 0; i8 < ag.a.size(); ++i8) {
                    localObject15 = (o) ag.a.get(i8);
                    if ((!(paramBoolean)) && (1 == ((o) localObject15).d))
                        continue;
                    localObject14 = ((o) localObject15).a();
                    ((JSONArray) localObject13).put(localObject14);
                }
            }
            if (localj.e != null) {
                localObject16 = localj.e.entrySet().iterator();
                localObject17 = null;
                while (((Iterator) localObject16).hasNext()) {
                    localObject18 = (Map.Entry) ((Iterator) localObject16).next();
                    localObject19 = (String) ((Map.Entry) localObject18).getKey();
                    localObject17 = (Vector) ((Map.Entry) localObject18).getValue();
                    if (((String) localObject19).equals(localn.a)) {
                        if (localObject13 == null) {
                            localObject12 = new JSONObject();
                            localObject13 = new JSONArray();
                        }
                        for (int i10 = 0; i10 < ((Vector) localObject17).size(); ++i10) {
                            localObject15 = (o) ((Vector) localObject17).get(i10);
                            localObject14 = ((o) localObject15).a();
                            ((JSONArray) localObject13).put(localObject14);
                        }
                    }
                    else {
                        JSONArray localJSONArray6 = new JSONArray();
                        for (int i12 = 0; i12 < ((Vector) localObject17).size(); ++i12) {
                            localObject15 = (o) ((Vector) localObject17).get(i12);
                            localObject14 = ((o) localObject15).a();
                            localJSONArray6.put(localObject14);
                        }
                        if (localObject12 == null)
                            localObject12 = new JSONObject();
                        ((JSONObject) localObject12).put((String) localObject19, localJSONArray6);
                    }
                }
            }
            if ((localObject13 != null) && (((JSONArray) localObject13).length() > 0) && (localObject12 != null))
                ((JSONObject) localObject12).put(localn.a, localObject13);
            if ((localObject12 != null) && (((JSONObject) localObject12).length() > 0))
                localJSONObject1.put("task", localObject12);
            Object localObject16 = null;
            Object localObject17 = null;
            Object localObject18 = null;
            Object localObject19 = null;
            if (r.a != null) {
                localObject16 = new JSONObject();
                localObject17 = new JSONArray();
                for (int i11 = 0; i11 < r.a.size(); ++i11) {
                    localObject19 = (h) r.a.get(i11);
                    localObject18 = ((h) localObject19).a();
                    ((JSONArray) localObject17).put(localObject18);
                }
            }
            if (localj.f != null) {
                localObject20 = localj.f.entrySet().iterator();
                localObject21 = null;
                while (((Iterator) localObject20).hasNext()) {
                    localObject22 = (Map.Entry) ((Iterator) localObject20).next();
                    localObject23 = (String) ((Map.Entry) localObject22).getKey();
                    localObject21 = (Vector) ((Map.Entry) localObject22).getValue();
                    if (((String) localObject23).equals(localn.a)) {
                        if (localObject17 == null) {
                            localObject16 = new JSONObject();
                            localObject17 = new JSONArray();
                        }
                        for (int i13 = 0; i13 < ((Vector) localObject21).size(); ++i13) {
                            localObject19 = (h) ((Vector) localObject21).get(i13);
                            localObject18 = ((h) localObject19).a();
                            ((JSONArray) localObject17).put(localObject18);
                        }
                    }
                    else {
                        JSONArray localJSONArray7 = new JSONArray();
                        for (int i15 = 0; i15 < ((Vector) localObject21).size(); ++i15) {
                            localObject19 = (h) ((Vector) localObject21).get(i15);
                            localObject18 = ((h) localObject19).a();
                            localJSONArray7.put(localObject18);
                        }
                        if (localObject16 == null)
                            localObject16 = new JSONObject();
                        ((JSONObject) localObject16).put((String) localObject23, localJSONArray7);
                    }
                }
            }
            if ((localObject17 != null) && (localObject16 != null))
                ((JSONObject) localObject16).put(localn.a, localObject17);
            if (localObject16 != null)
                localJSONObject1.put("buy", localObject16);
            Object localObject20 = null;
            Object localObject21 = null;
            Object localObject22 = null;
            Object localObject23 = null;
            if (ah.a != null) {
                localObject20 = new JSONObject();
                localObject21 = new JSONArray();
                for (int i14 = 0; i14 < ah.a.size(); ++i14) {
                    localObject23 = (p) ah.a.get(i14);
                    localObject22 = ((p) localObject23).a();
                    ((JSONArray) localObject21).put(localObject22);
                }
            }
            if (localj.g != null) {
                localObject24 = localj.g.entrySet().iterator();
                localObject25 = null;
                while (((Iterator) localObject24).hasNext()) {
                    localObject26 = (Map.Entry) ((Iterator) localObject24).next();
                    localObject27 = (String) ((Map.Entry) localObject26).getKey();
                    localObject25 = (Vector) ((Map.Entry) localObject26).getValue();
                    if (((String) localObject27).equals(localn.a)) {
                        if (localObject21 == null) {
                            localObject20 = new JSONObject();
                            localObject21 = new JSONArray();
                        }
                        for (int i16 = 0; i16 < ((Vector) localObject25).size(); ++i16) {
                            localObject23 = (p) ((Vector) localObject25).get(i16);
                            localObject22 = ((p) localObject23).a();
                            ((JSONArray) localObject21).put(localObject22);
                        }
                    }
                    else {
                        localObject28 = new JSONArray();
                        for (int i17 = 0; i17 < ((Vector) localObject25).size(); ++i17) {
                            localObject23 = (p) ((Vector) localObject25).get(i17);
                            localObject22 = ((p) localObject23).a();
                            ((JSONArray) localObject28).put(localObject22);
                        }
                        if (localObject20 == null)
                            localObject20 = new JSONObject();
                        ((JSONObject) localObject20).put((String) localObject27, localObject28);
                    }
                }
            }
            if ((localObject21 != null) && (localObject20 != null))
                ((JSONObject) localObject20).put(localn.a, localObject21);
            if (localObject20 != null)
                localJSONObject1.put("use", localObject20);
            Object localObject24 = new w(paramContext, localJSONArray1.length());
            Object localObject25 = ((w) localObject24).a();
            localJSONObject1.put("header", localObject25);
            Object localObject26 = ab.b(paramContext);
            if (localObject26 != null)
                localJSONObject1.put("player", localObject26);
            Object localObject27 = v.a(localn.a);
            if (localObject27 != null)
                localJSONObject1.put("exception", localObject27);
            str1 = localJSONObject1.toString();
            str1 = ai.c(str1);
            Object localObject28 = ai.r(paramContext);
            ai.a((String) localObject28, str1);
            if (paramBoolean)
                localn.a();
            aa.a();
            u.a();
            y.a();
            ag.a();
            r.a();
            ah.a();
            ab.a();
            localj.a();
        } catch (Exception localException1) {
            x.a(a, localException1);
        } catch (Error localError1) {
            x.a(a, localError1);
        }
    }
}